/*
 * $Id: DisciplinePlanningItemAction.java 1724 2011-08-30 09:14:20Z abie $
 * 
 * Copyright (c) 2001-2008 Accentrix Company Limited. All Rights Reserved.
 * 
 * Accentrix Company Limited. ("Accentrix") retains copyright on all text, source
 * and binary code contained in this software and documentation. Accentrix grants
 * Licensee a limited license to use this software, provided that this copyright
 * notice and license appear on all copies of the software. The software source
 * code is provided for reference purposes only and may not be copied, modified 
 * or distributed.
 * 
 * THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS," WITHOUT ANY WARRANTY OF
 * ANY KIND UNLESS A SEPARATE WARRANTIES IS PURCHASED FROM ACCENTRIX AND REMAINS
 * VALID.  ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ACCENTRIX SHALL NOT BE LIABLE
 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING OR MODIFYING THE
 * SOFTWARE OR ITS DERIVATIVES.
 * 
 * IN NO EVENT WILL ACCENTRIX BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE
 * USE OF OR INABILITY TO USE SOFTWARE, EVEN IF ACCENTRIX HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */
package com.lightsaber.trade.cloth.web.planfirst;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.lightsaber.trade.core.common.treegrid.GridConstants;
import com.lightsaber.trade.core.web.BaseAction;
import com.lightsaber.trade.cloth.entity.planning.Level1Planning;
import com.lightsaber.trade.cloth.service.planfirst.DisciplinePlanningItemManager;
import com.lightsaber.trade.cloth.service.planfirst.PlanFirstLevelManager;

@Namespace("/planfirst")
public class DisciplinePlanningItemAction extends BaseAction {
    private static final long serialVersionUID = -8065264006998747448L;

    @Autowired
    DisciplinePlanningItemManager disciplinePlanningItemManager;
    @Autowired
    private transient PlanFirstLevelManager planFirstLevelManager;
    private String level1PlanningId;
    private String categoryNodeId;
    private String treeGridData;
    private Operator operator;
    private Level1Planning level1Planning;

    private String planningId;

    @Override
    public String execute() {
        return list();
    }

    public String list() {
        level1Planning = planFirstLevelManager.get(level1PlanningId);
        setLevel1Planning(level1Planning);
        return SUCCESS;
    }

    public void data() throws Exception {
        treeGridData = disciplinePlanningItemManager.generateTreeGrid(level1PlanningId,
                categoryNodeId);

        Struts2Utils.renderXml(treeGridData);
    }

    public String save() throws Exception {
        disciplinePlanningItemManager.save(treeGridData, level1PlanningId, categoryNodeId);
        Struts2Utils.renderXml(GridConstants.SUCESSFULLY);
        return null;
    }

    public String getLevel1PlanningId() {
        return level1PlanningId;
    }

    public void setLevel1PlanningId(final String level1PlanningId) {
        this.level1PlanningId = level1PlanningId;
    }

    public String getCategoryNodeId() {
        return categoryNodeId;
    }

    public void setCategoryNodeId(final String categoryNodeId) {
        this.categoryNodeId = categoryNodeId;
    }

    public String getTreeGridData() {
        return treeGridData;
    }

    public void setTreeGridData(final String treeGridData) {
        this.treeGridData = treeGridData;
    }

    public Operator getOperator() {
        return operator;
    }

    public void setOperator(final Operator operator) {
        this.operator = operator;
    }

    public String getPlanningId() {
        return planningId;
    }

    public void setPlanningId(final String planningId) {
        this.planningId = planningId;
    }

    public Level1Planning getLevel1Planning() {
        return level1Planning;
    }

    public void setLevel1Planning(Level1Planning level1Planning) {
        this.level1Planning = level1Planning;
    }

}
